package com.zhc.validate.processor;


import com.zhc.validate.annotation.Algorithm;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Method;
import java.util.Set;

@Slf4j
public class AlgorithmAnnotationProcessor {

    public static Set<com.zhc.validate.entity.Algorithm> processor(Class<?> clazz) {
        Set<com.zhc.validate.entity.Algorithm> algorithms = new java.util.HashSet<>();
        try {
            Method[] methods = clazz.getDeclaredMethods();
            for (Method method : methods) {
                // 获取被@Algorithm注解标注的方法
                if (method.isAnnotationPresent(Algorithm.class)) {
                    Algorithm algorithm = method.getAnnotation(Algorithm.class);
                    int priority = algorithm.priority();
                    algorithms.add(new com.zhc.validate.entity.Algorithm(priority, method));
                }
            }
            return algorithms;
        } catch (Exception e) {
            log.error("Error occurred while processing classes: {}", e.getMessage(), e);
            return Set.of(); // 返回空集合
        }
    }

}
